package org.dawfinn.droiditarian;

import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dawfinn.droiditarian.server.data.DeedLocation;
import org.dawfinn.droiditarian.server.data.PMF;

@SuppressWarnings("serial")
public class UpdateDeedLocationsServlet extends HttpServlet {

	@SuppressWarnings("unchecked")
	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(DeedLocation.class);

		// geoPt != null is true for all old DeedLocations
		query.setFilter("geoPt != null");
		query.setRange(0, 25);

		List<DeedLocation> results = (List<DeedLocation>) query.execute();
//		Geohash gh = Geohash.getInstance();
//		ReverseGeocoder rg = new ReverseGeocoder();
//		Transaction transaction = pm.currentTransaction();

//		for (DeedLocation result : results) {
//			transaction.begin();
//			
//
//			transaction.commit();
//		}

		pm.close();

		Logger.getLogger(getClass().getName()).log(Level.INFO,
				"Success: updated " + results.size() + " DeedLocation objects");
	}
}
